/**
 * 
 */
package com.lehecai.core.api.event;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * 用户道具
 * @author He Wang
 *
 */
public class UserPropInfo extends AbstractApiResultBean {
	
	public static final String QUERY_UID = "uid";

	private String id;
	private Long uid;		       //编码
	private String propId;         //名称
	private PropType type;	       //道具类型
	private Integer num;           //道具属性
	private Date updatedTime;      //创建时间
	private String propName;       //道具名称
	private String typeName;       //道具类型名称
	private PropInfoStatus status;  //道具状态
	private Date expiredTime;       //过期时间

	public static UserPropInfo convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		UserPropInfo propInfo = new UserPropInfo();
		propInfo.uid = getLong(object, "uid");
		propInfo.id = getString(object, "id");
		propInfo.propId = getString(object, "prop_id");
		propInfo.type = PropType.getItem(getInt(object, "type"));
		propInfo.num = getInt(object, "num");
		propInfo.updatedTime = CoreDateUtils.parseDate(getString(object, "update_at"), CoreDateUtils.DATETIME);
		propInfo.propName = getString(object, "prop_name");
		propInfo.typeName = getString(object, "type_name");
		if (object.containsKey("status")) {
			propInfo.status = PropInfoStatus.getItem(getInt(object, "status"));
		}
		if (object.containsKey("expired_time")) {
			Long expiredTimeSecond = getLong(object, "expired_time");
			propInfo.expiredTime = new Date();
			propInfo.expiredTime.setTime(expiredTimeSecond * 1000);
		}
		return propInfo;
	}
	
	public static List<UserPropInfo> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<UserPropInfo> list = new ArrayList<UserPropInfo>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public void setType(PropType type) {
		this.type = type;
	}

	public PropType getType() {
		return type;
	}

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public String getPropId() {
		return propId;
	}

	public void setPropId(String propId) {
		this.propId = propId;
	}

	public Integer getNum() {
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public String getPropName() {
		return propName;
	}

	public void setPropName(String propName) {
		this.propName = propName;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public PropInfoStatus getStatus() {
		return status;
	}

	public void setStatus(PropInfoStatus status) {
		this.status = status;
	}

	public Date getExpiredTime() {
		return expiredTime;
	}

	public void setExpiredTime(Date expiredTime) {
		this.expiredTime = expiredTime;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
